<?php
/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 3/29 0029
 * Time: 19:03
 */

namespace app\index\model;


use think\Model;

class Shop extends Model
{
    /**
     * 获取所有门店
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getall(){
        return $this->join("y_merchant","y_merchant.id=y_shop.merchantid","left")->field("y_shop.*,y_merchant.mername")->select();
    }

    /**
     * 获取一个门店
     * @param $shopid
     * @return array|false|\PDOStatement|string|Model
     */
    public function getone($shopid){
        return $this->join("y_merchant","y_merchant.id=y_shop.merchantid","left")->field("y_shop.*,y_merchant.mername")->where(['y_shop.id'=>$shopid])->find();
    }

    /**
     * 获取一个商户下的所有门店
     * @param $merchantid
     */
    public function getonemer($merchantid){
        return $this->where(["merchantid"=>$merchantid])->select();
    }

    /**
     * 获得店面
     * @param $shopid
     * @return mixed
     */
    public function getname($shopid){
        return $this->where(["id"=>$shopid])->column("shopname")[0];
    }

    /**
     * 根据ID获得该商户下的所有门店
     * @param $managerid
     * @param $usertype
     */
    public function getallbyid($managerid,$usertype){
        if ($usertype==1){
            $merchantid=\model("manager")->where("id",$managerid)->column("merchantid")[0];
        }else{
            $shopid=\model("manager")->where("id",$managerid)->column("shopid")[0];
            $merchantid=$this->where("id",$shopid)->column("merchantid")[0];
        }
        return $this->where("merchantid",$merchantid)->field("id,shopname")->select();
    }

}